]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
box-layout: Support replacing layout manager
authorFlorian Müllner <fmuellner@gnome.org>
Sun, 4 Oct 2015 01:06:34 +0000 (03:06 +0200)
committerFlorian Müllner <fmuellner@gnome.org>
Thu, 15 Oct 2015 17:21:15 +0000 (19:21 +0200)
There is nothing preventing callers from replacing the internal
layout manager, and as long as the replacement is a (or derives
from) ClutterBoxLayout, everything should work fine except for
losing a bit of automatic property mapping - and the latter is
easily fixable by moving the setup out of the constructor.

https://bugzilla.gnome.org/show_bug.cgi?id=708472

src/st/st-box-layout.c

index 63e2ff717ee99424b908e01ea4a187f1766a83d8..8f01b296cfb88787d6a94756c517221dd004559a 100644 (file)
@@ -562,6 +562,24 @@ layout_notify (GObject    *object,
     g_object_notify (self, prop_name);
 }
 
+static void
+on_layout_manager_notify (GObject    *object,
+                          GParamSpec *pspec,
+                          gpointer    user_data)
+{
+  ClutterActor *actor = CLUTTER_ACTOR (object);
+  ClutterLayoutManager *layout = clutter_actor_get_layout_manager (actor);
+
+  g_warn_if_fail (CLUTTER_IS_BOX_LAYOUT (layout));
+
+  if (layout == NULL)
+    return;
+
+  g_signal_connect_swapped (layout, "layout-changed",
+                            G_CALLBACK (clutter_actor_queue_relayout), actor);
+  g_signal_connect (layout, "notify", G_CALLBACK (layout_notify), object);
+}
+
 static void
 st_box_layout_class_init (StBoxLayoutClass *klass)
 {
@@ -614,14 +632,11 @@ st_box_layout_class_init (StBoxLayoutClass *klass)
 static void
 st_box_layout_init (StBoxLayout *self)
 {
-  ClutterLayoutManager *layout;
-
   self->priv = BOX_LAYOUT_PRIVATE (self);
-  layout = clutter_box_layout_new ();
-  g_signal_connect_swapped (layout, "layout-changed",
-                            G_CALLBACK (clutter_actor_queue_relayout), self);
-  g_signal_connect (layout, "notify", G_CALLBACK (layout_notify), self);
-  clutter_actor_set_layout_manager (CLUTTER_ACTOR (self), layout);
+
+  g_signal_connect (self, "notify::layout-manager",
+                    G_CALLBACK (on_layout_manager_notify), NULL);
+  clutter_actor_set_layout_manager (CLUTTER_ACTOR (self), clutter_box_layout_new ());
 }
 
 /**